#include "../comm.h"

class Solution {
public:
    int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {
        if(plants.size() <= 2) return 0;
        int n = plants.size();
        int l = 1, r = n - 2;
        int nowA = capacityA - plants[0], nowB = capacityB - plants[n - 1];
        cout << nowA << ' ' << nowB << endl;
        int ans = 0;
        while(l <= r)
        {
            if(l == r)
            {
                int mmax = max(nowA, nowB);
                if(mmax < plants[l])
                    ++ans;
            }
            else
            {
                if(nowA < plants[l])
                {
                    ++ans;
                    nowA = capacityA - plants[l];
                }
                else
                    nowA -= plants[l];
                if(nowB < plants[r])
                {
                    ++ans;
                    nowB = capacityB - plants[r];
                }
                else
                    nowB -= plants[r];
            }
            ++l, --r;
        }
        return ans;
    }
};